package com.hope.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RequiredArgsConstructor
@RestController
@RequestMapping("/ai")
// 智能助手ai
public class ChatController {

    private final ChatClient chatChatClient;

    @RequestMapping(value = "/chat", produces = "text/html;charset=utf-8")
    public Flux<String> chat(String prompt, String chatId) {
        return chatChatClient
                .prompt()
                .user(prompt)
                .advisors(a -> a.param(ChatMemory.CONVERSATION_ID, chatId))
                .stream()
                .content();
    }
}
//    @RequestMapping(value = "/chat", produces = "text/html;charset=utf-8")
//    public String chat(String prompt) {
//        return chatClient.prompt()
//                .user(prompt)
//                .call()
//                .content();
//    }

//    @RequestMapping(value = "/chat", produces = "text/html;charset=utf-8")
//    // @CrossOrigin("http://localhost:5173")
//    public Flux<String> chat(@RequestParam("prompt") String prompt, @RequestParam("chatId") String chatId) {
//        return chatClient.prompt()
//                .user(prompt)// 设置用户输入
//                .advisors(a->a.param(ChatMemory.CONVERSATION_ID,chatId))// 设置会话ID
//                .stream()// 开启流式对话
//                .content();// 获取对话内容
//    }
//}
